package com.zhou.demo.interfaceclass;

import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.zhou.demo.callback.ShortCommentsCallback;
import com.zhou.demo.url.ZhihuUrl;

import java.io.IOException;

/**
 * Created by 11065 on 2016/8/11.
 */
public class ShortCommetsConnect implements ShortCommentsInterface {
    @Override
    public void getShortComments(String id, final ShortCommentsCallback callback) {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(ZhihuUrl.SHORTCOMMENT1+id+ZhihuUrl.LONGCOMMET2)
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
                callback.onShortCommentsFail(e.getMessage());
            }

            @Override
            public void onResponse(Response response) throws IOException {
                callback.onShortCommentsSuccess(response.body().string());
            }
        });
    }
}
interface ShortCommentsInterface{
    void getShortComments(String id, ShortCommentsCallback callback);
}
